package com.joinlabs.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.joinlabs.entity.Comment;
import com.joinlabs.entity.Forwarding;
import com.joinlabs.entity.User;
import com.joinlabs.entity.Weibo;
import com.joinlabs.service.IFindCommentByidService;
import com.joinlabs.service.IFindweiboDetialByidService;
import com.joinlabs.service.ITranstoService;
import com.joinlabs.service.IUserService;

@Controller
@RequestMapping("/TrantoPage")
@SessionAttributes(names= {"commentlist","weiboDetail","user"})
public class TranstoAction {
	 @Resource
	   private IUserService userService;//用户
	 @Resource
	   private IFindCommentByidService findCommentService;//评论内容
	  @Resource 
	  private IFindweiboDetialByidService weiboDetialByidService;//找微博详情
	  @Resource
	  private ITranstoService trantoService;

		 @RequestMapping("/Tranto")
		 @ResponseBody
		 public Object comment(ModelMap map,String WBid) {
			
			 System.out.println("WBid:"+WBid);
			 List<Comment> commentlist=findCommentService.selectAllCommentByWBid(Long.parseLong(WBid));
			 map.addAttribute("commentlist",commentlist);
			 //通过传入id查询微博详情
			Weibo  weiboDetail =weiboDetialByidService.selectDetailMsg(Long.parseLong(WBid));
				map.addAttribute("weiboDetail",weiboDetail);
				for (Comment comment : commentlist) {
					 System.out.println("commentlist皮鞥了；"+comment);
				}
			 System.out.println("weiboDetail"+weiboDetail);
				return new String("success");
			 
		 }
	  
		 @RequestMapping("/showTranto")
		 public String select() {
			 
			 return "/hotPage/Transto";
		 }
		 //插入转发
	    @RequestMapping("/tranferweibo")
		 @ResponseBody
		 public Object tranferweibo(ModelMap map,String WBId,String msg) {
	    	//获取用户
			User user = (User) map.get("user");
			Long userid=user.getUserId();
			System.out.println("user**************"+userid);
			//获取微博id
			 Long weiboId=Long.parseLong(WBId);
			 System.out.println("weiboId**************"+weiboId);
		    Forwarding forward=new Forwarding();
			// 获取发布时间
			  Date date = new Date();
			  //forward.setForwardingId();
			  forward.setForwardingContent(msg); 
			  forward.setUserId(userid);
			  forward.setWeiboId(weiboId);
			  forward.setForwardingTime(date);
         int row=trantoService.insertforwarding(forward);
			 return "success";
		 }
		
}
